package com.qixin.web.controller.TencentMap;

import com.alibaba.fastjson.JSONObject;
import com.qixin.web.bean.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 张子艺 on 2018/9/26.
 *
 */
@Controller
@RequestMapping("/Map")
public class MapController {
    private static final Logger logger = LoggerFactory.getLogger(MapController.class);
    @Value("${TencentMapAppID}")
    String appid="";
    /**
     * 跳转定位地图页面
     */
    @RequestMapping("/GpsLocation.html")
    public String GpsLocation(Model model){
        logger.info("腾讯地图APPID："+appid);
        model.addAttribute("appid",appid);
        return "/Map/searchChargeByMap";
    }


    /**
     *
     * @param model 往页面传值
     * @param charegeLat 充电桩lat
     * @param charegeLng 充电桩lng
     * @param locationLat  用户定位lat
     * @param locationLng   用户定位lng
     * @return
     */

    @RequestMapping("/Navigation.html")
    public String Navigation(Model model,String charegeLat, String charegeLng, String locationLat, String locationLng){
        logger.info("选中需要导航的充电桩坐标 lat:"+charegeLat+"   lng:"+charegeLng);
        logger.info("当前定位坐标 lat:"+locationLat+"   lng"+locationLng);
        model.addAttribute("charegeLat",charegeLat);
        model.addAttribute("charegeLng",charegeLng);
        model.addAttribute("locationLat",locationLat);
        model.addAttribute("locationLng",locationLng);
        return "/Map/Navigation";
    }

    /**
     * 测试充电桩经纬度坐标  标注
     * @return
     */
    @RequestMapping("/chargeLatLng")
    @ResponseBody
    public String chargeLatLng(){
        List<Map> list=new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Map map=new Map();
            map.setContent("这是第"+i+"个充电桩");
            map.setLat("3"+i+".916527");
            map.setLng(116.397128+"");
            list.add(map);
        }
        return JSONObject.toJSONString(list);
    }
}
